
/**   
 * @Title: UserInfoDao.java 
 * @Package com.neusoft.neumooc.dao 
 * @Description: TODO 
 * @author acer   
 * @date 2016年10月31日 上午9:41:37 
*/

package com.neusoft.neumooc.dao;
import java.util.List;
import org.springframework.stereotype.Repository;
import com.neusoft.core.common.BaseDAO;
import com.neusoft.core.common.exception.DAOException;
import com.neusoft.neumooc.VO.UserVO;
/** 
 * @ClassName: UserInfoDao 
 * @Description: TODO 
 * @author Fuyongjun
 * @date 2016年10月31日
 */
@Repository
public class UserInfoDaoImpl extends BaseDAO implements UserInfoDao{
	/** 
	 * @Fields UPDATE_MENU : TODO 获取用户信息
	 */ 
	private final static String GET_USER_INFO = "select wemall_user.uid,wemall_user.username as userName,wemall_user.phone,wemall_user.password,wemall_user.address, wemall_user.time from wemall_user";
	/** 
	 * @Fields UPDATE_MENU : TODO 获取用户数量
	 */ 
	private final static String GET_USER_COUNT="select count(1) from  wemall_user";
	/** 
	 * @Fields UPDATE_MENU : TODO 插入用户
	 */ 

	private final static String INSERT_INTO_USER="insert into wemall_user(id,uid,username,phone,password,address,time)values(:id,:uid,:userName,:phone,:password,:address,now())";
	
	
	private static final String INSERT_REPEAT_REPEAT = "select count(1) from wemall_user as userName where userName=?";//判断是否重复
	
	@Override
	public int getUserCount() throws DAOException {
		return this.queryForInteger(GET_USER_COUNT);
	}
	/** 
	 * @Title: getUsers 
	 * @Description: TODO 
	 * @param pageNo
	 * @param pageSize
	 * @return
	 * @throws DAOException
	 */
	@Override
	public List<UserVO> getUsers(int pageNo, int pageSize) throws DAOException {
	
		return this.getPageData(GET_USER_INFO, UserVO.class, pageNo, pageSize);
	}
	
	/** 
	 * @Title: InsertUsers 
	 * @Description: TODO 
	 * @param userVO
	 * @return
	 * @throws DAOException
	 */
	
	@Override
	public int insertUsers(UserVO userVO) throws DAOException {
		return  this.update(INSERT_INTO_USER,userVO);
	}
	
	/** 
	 * @Title: checkRepeat 
	 * @Description: TODO 
	 * @param name
	 * @return
	 * @throws DAOException
	 */
	
	@Override
	public boolean checkRepeat(String name) throws DAOException {
	
		int t= this.queryInteger(INSERT_REPEAT_REPEAT, new Object[]{name});
		if(t>=1)
		{
			return false;	
		}
		else
		{
			return true;
		}
	}
}
